WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
logging.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// third_party include
22#include <map>
23#include <string>
24
25// spdlog include
26#include "spdlog/spdlog.h"
27#include "spdlog/async.h"
28#include "spdlog/sinks/stdout_color_sinks.h"
29
30// enable the use of ostream operator<<
31#include "spdlog/fmt/ostr.h"
32
33// Wolf includes
35
36namespace wolf
37{
38namespace internal
39{
40namespace do_not_enter_where_the_wolf_lives
41{
42#define __INTERNAL_WOLF_MAIN_LOGGER_NAME_ "wolf_main_console"
43
44static constexpr auto repeated_brace = std::make_tuple(
45 "{}",
46 "{}{}",
47 "{}{}{}",
48 "{}{}{}{}",
49 "{}{}{}{}{}",
50 "{}{}{}{}{}{}",
51 "{}{}{}{}{}{}{}",
52 "{}{}{}{}{}{}{}{}",
53 "{}{}{}{}{}{}{}{}{}",
54 "{}{}{}{}{}{}{}{}{}{}",
55 "{}{}{}{}{}{}{}{}{}{}{}",
56 "{}{}{}{}{}{}{}{}{}{}{}{}",
57 "{}{}{}{}{}{}{}{}{}{}{}{}{}",
58 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
59 "{}{}{}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}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
91 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
92 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
93 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
94 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}"); // up to
95 // 50
96 // args.
97 // should
98 // be
99 // enough
103{
104 public:
107 Logger(const std::string& name);
108
111 Logger(std::string&& name);
112
115 ~Logger();
116
117 // Not copyable/movable
120 Logger(Logger&) = delete;
121
124 void operator=(Logger&) = delete;
125
128 Logger(Logger&&) = delete;
129
132 void operator=(Logger&&) = delete;
133
136 template <typename... Args>
137 void info(Args&&... args) const;
138
141 template <typename... Args>
142 void warn(Args&&... args) const;
143
146 template <typename... Args>
147 void error(Args&&... args) const;
148
151 template <typename... Args>
152 void debug(Args&&... args) const;
153
156 template <typename... Args>
157 void trace(Args&&... args) const;
158
161 bool set_async_queue(const std::size_t q_size);
162
165 void set_pattern(const std::string& p);
166
167 protected:
168 const std::string log_name_;
169
170 std::shared_ptr<spdlog::logger> console_;
171};
172
173inline Logger::Logger(const std::string& name) : log_name_(name)
174{
175 // Create main logger
176 console_ = spdlog::stdout_color_mt(log_name_);
177
178#ifdef _WOLF_TRACE
179 console_->set_level(spdlog::level::trace);
180#endif
181
182 // Enable asynchronous logging
183 // Queue size must be a power of 2
184 spdlog::init_thread_pool(4096, 1);
185
187 // [thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
188 // set_pattern("[%t][%H:%M:%S.%F][%l] %v");
189
190 // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds] #log-content
191 // set_pattern("[%l][%x - %H:%M:%S.%F] %v");
192
193 // [log type][hour:minutes:seconds] #log-content
194 // set_pattern("%^[%l][%H:%M:%S] %v%$");
195
196 // [log type]#log-content
197 set_pattern("%^[%l]%v%$");
198 else
199 // [logger name][thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
200 // set_pattern("[" + log_name_ + "]" +"[%t][%H:%M:%S.%F][%l] %v");
201
202 // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds][logger name] #log-content
203 set_pattern("%^[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v%$");
204}
205
206inline Logger::Logger(std::string&& name) : log_name_(std::forward<std::string>(name))
207{
208 // Create main logger
209 console_ = spdlog::stdout_color_mt(log_name_);
210
211#ifdef _WOLF_TRACE
212 console_->set_level(spdlog::level::trace);
213#endif
214
215 // Enable asynchronous logging
216 // Queue size must be a power of 2
217 spdlog::init_thread_pool(4096, 1);
218
220 // [thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
221 // set_pattern("[%t][%H:%M:%S.%F][%l] %v");
222
223 // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds] #log-content
224 // set_pattern("[%l][%x - %H:%M:%S.%F] %v");
225
226 // [log type][hour:minutes:seconds] #log-content
227 // set_pattern("%^[%l][%H:%M:%S] %v%$");
228
229 // [log type][source_file line][function] #log-content
230 set_pattern("%^[%l]%v%$");
231 else
232 // [logger name][thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
233 // set_pattern("[" + log_name_ + "]" +"[%t][%H:%M:%S.%F][%l] %v");
234
235 // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds][logger name] #log-content
236 set_pattern("%^[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v%$");
237}
238
240{
241 spdlog::drop(log_name_);
242}
243
244template <typename... Args>
245void Logger::info(Args&&... args) const
246{
247#if FMT_VERSION >= 90000 // from v9.0 FMT does not takes ostream formatter
248 console_->info(std::get<sizeof...(args) - 1>(repeated_brace), fmt::streamed(std::forward<Args>(args))...);
249#else
250 console_->info(std::get<sizeof...(args) - 1>(repeated_brace), std::forward<Args>(args)...);
251#endif
252}
253
254template <typename... Args>
255void Logger::warn(Args&&... args) const
256{
257#if FMT_VERSION >= 90000 // from v9.0 FMT does not takes ostream formatter
258 console_->warn(std::get<sizeof...(args) - 1>(repeated_brace), fmt::streamed(std::forward<Args>(args))...);
259#else
260 console_->warn(std::get<sizeof...(args) - 1>(repeated_brace), std::forward<Args>(args)...);
261#endif
262}
263
264template <typename... Args>
265void Logger::error(Args&&... args) const
266{
267#if FMT_VERSION >= 90000 // from v9.0 FMT does not takes ostream formatter
268 console_->error(std::get<sizeof...(args) - 1>(repeated_brace), fmt::streamed(std::forward<Args>(args))...);
269#else
270 console_->error(std::get<sizeof...(args) - 1>(repeated_brace), std::forward<Args>(args)...);
271#endif
272}
273
274template <typename... Args>
275void Logger::debug(Args&&... args) const
276{
277#if FMT_VERSION >= 90000 // from v9.0 FMT does not takes ostream formatter
278 console_->debug(std::get<sizeof...(args) - 1>(repeated_brace), fmt::streamed(std::forward<Args>(args))...);
279#else
280 console_->debug(std::get<sizeof...(args) - 1>(repeated_brace), std::forward<Args>(args)...);
281#endif
282}
283
284template <typename... Args>
285void Logger::trace(Args&&... args) const
286{
287#if FMT_VERSION >= 90000 // from v9.0 FMT does not takes ostream formatter
288 console_->trace(std::get<sizeof...(args) - 1>(repeated_brace), fmt::streamed(std::forward<Args>(args))...);
289#else
290 console_->trace(std::get<sizeof...(args) - 1>(repeated_brace), std::forward<Args>(args)...);
291#endif
292}
293
294inline bool Logger::set_async_queue(const std::size_t q_size)
295{
296 bool p2 = q_size % 2 == 0;
297
298 if (p2) spdlog::init_thread_pool(q_size, 1);
299
300 return q_size;
301}
302
303inline void Logger::set_pattern(const std::string& p)
304{
305 console_->set_pattern(p);
306}
307
308using LoggerPtr = std::unique_ptr<Logger>;
309
313{
314 public:
317 LoggerManager() = default;
318
321 ~LoggerManager() = default;
322
325 bool exists(const std::string& name) const
326 {
327 std::lock_guard<std::mutex> lock(mut_);
328 return existsImpl(name);
329 }
330
333 const Logger& getLogger(const std::string& name) /*const*/
334 {
335 std::lock_guard<std::mutex> lock(mut_);
336
337 if (!existsImpl(name)) addLogger(name);
338
339 return *(logger_map_.at(name));
340 }
341
342 protected:
343 mutable std::mutex mut_;
344
345 std::map<const std::string, const LoggerPtr> logger_map_;
346
349 bool addLogger(const std::string& name)
350 {
352 const bool created =
353 existsImpl(name) ? false : logger_map_.emplace(name, std::make_unique<Logger>(name)).second;
354 return created;
355 }
356
359 bool existsImpl(const std::string& name) const
360 {
361 return (logger_map_.find(name) != logger_map_.end());
362 }
363};
364
365} /* namespace do_not_enter_where_the_wolf_lives */
366
369
376inline bool isMemberFunctionOf(const std::string& _function_signature, const std::string& _class_name)
377{
378 // qualified name of the function (with return type): remove parameters and anything after them
379 const std::string name = _function_signature.substr(0, _function_signature.find('('));
380 const std::string scope = "wolf::" + _class_name + "::";
381
382 // the scope has to be at the beginning (no return type, e.g. constructors) or just after the return type
383 for (auto pos = name.find(scope); pos != std::string::npos; pos = name.find(scope, pos + 1))
384 if (pos == 0 or name[pos - 1] == ' ') return true;
385
386 return false;
387}
388
389} /* namespace internal */
390} /* namespace wolf */
391
392#define WOLF_STRINGIFY(x) #x
393#define WOLF_STR_HELPER(x) WOLF_STRINGIFY(x)
394
395/* Full signature of the enclosing function, e.g. "void wolf::ProcessorX::preProcess()" (used by WOLF_PROC_DEBUG).
396 * Not boost::source_location::function_name(): depending on the boost version and compiler, it may be only the
397 * unqualified function name (e.g. "preProcess").
398 */
399#if defined(__GNUC__) || defined(__clang__)
400#define WOLF_PRETTY_FUNCTION __PRETTY_FUNCTION__
401#elif defined(_MSC_VER)
402#define WOLF_PRETTY_FUNCTION __FUNCSIG__
403#endif
404
405/* Logging macros
406 *
407 * WOLF_DEBUG, WOLF_TRACE (and their _COND and _NAMED versions) only print if _WOLF_DEBUG / _WOLF_TRACE are defined.
408 * Otherwise, they expand to an empty statement. To behave the same in all builds, they are wrapped in
409 * 'do { ... } while (0)', so that:
410 * - they are a single statement, safe as the body of an if/else without braces:
411 * if (a) WOLF_DEBUG("..."); else foo();
412 * - the ';' after them is mandatory (a missing ';' is a compile error in all builds). With an empty expansion, a
413 * missing ';' would make the next statement the body of a preceding 'if' only in release builds:
414 * if (a) WOLF_DEBUG("...") // missing ';'
415 * foo(); // RELEASE: if (a) foo();
416 */
417
419
420#define WOLF_ASYNC_QUEUE_LOG_NAMED(name, ...) \
421 wolf::internal::WolfLoggerManager::get().getLogger(name).set_async_queue(x);
422
423#define WOLF_INFO_NAMED(name, ...) \
424 { \
425 char this_file[] = __FILE__; \
426 wolf::internal::WolfLoggerManager::get().getLogger(name).info( \
427 "[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
428 }
429#define WOLF_INFO_NAMED_COND(name, cond, ...) \
430 if (cond) WOLF_INFO_NAMED(name, __VA_ARGS__);
431
432#define WOLF_WARN_NAMED(name, ...) \
433 { \
434 char this_file[] = __FILE__; \
435 wolf::internal::WolfLoggerManager::get().getLogger(name).warn( \
436 "[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
437 }
438#define WOLF_WARN_NAMED_COND(name, cond, ...) \
439 if (cond) WOLF_WARN_NAMED(name, __VA_ARGS__);
440
441#define WOLF_ERROR_NAMED(name, ...) \
442 { \
443 char this_file[] = __FILE__; \
444 wolf::internal::WolfLoggerManager::get().getLogger(name).error( \
445 "[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
446 }
447#define WOLF_ERROR_NAMED_COND(name, cond, ...) \
448 if (cond) WOLF_ERROR_NAMED(name, __VA_ARGS__);
449
450#ifdef _WOLF_DEBUG
451#define WOLF_DEBUG_NAMED(name, ...) \
452 do \
453 { \
454 char this_file[] = __FILE__; \
455 wolf::internal::WolfLoggerManager::get().getLogger(name).debug( \
456 "[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
457 } while (0)
458#define WOLF_DEBUG_NAMED_COND(name, cond, ...) \
459 do \
460 { \
461 if (cond) WOLF_DEBUG_NAMED(name, __VA_ARGS__); \
462 } while (0)
463#else
464#define WOLF_DEBUG_NAMED(name, ...) \
465 do \
466 { \
467 } while (0)
468#define WOLF_DEBUG_NAMED_COND(name, cond, ...) \
469 do \
470 { \
471 } while (0)
472#endif
473
474#ifdef _WOLF_TRACE
475#define WOLF_TRACE_NAMED(name, ...) \
476 do \
477 { \
478 char this_file[] = __FILE__; \
479 wolf::internal::WolfLoggerManager::get().getLogger(name).trace( \
480 "[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
481 } while (0)
482#define WOLF_TRACE_NAMED_COND(name, cond, ...) \
483 do \
484 { \
485 if (cond) WOLF_TRACE_NAMED(name, __VA_ARGS__); \
486 } while (0)
487#else
488#define WOLF_TRACE_NAMED(name, ...) \
489 do \
490 { \
491 } while (0)
492#define WOLF_TRACE_NAMED_COND(name, cond, ...) \
493 do \
494 { \
495 } while (0)
496#endif
497
499
500#define WOLF_ASYNC_QUEUE_LOG(x) wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_).set_async_queue(x);
501
502#define WOLF_INFO(...) \
503 { \
504 char this_file[] = __FILE__; \
505 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
506 .info("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
507 }
508#define WOLF_INFO_COND(cond, ...) \
509 if (cond) WOLF_INFO(__VA_ARGS__);
510
511#define WOLF_WARN(...) \
512 { \
513 char this_file[] = __FILE__; \
514 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
515 .warn("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
516 }
517#define WOLF_WARN_COND(cond, ...) \
518 if (cond) WOLF_WARN(__VA_ARGS__);
519
520#define WOLF_ERROR(...) \
521 { \
522 char this_file[] = __FILE__; \
523 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
524 .error("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
525 }
526#define WOLF_ERROR_COND(cond, ...) \
527 if (cond) WOLF_ERROR(__VA_ARGS__);
528
529#ifdef _WOLF_DEBUG
530#define WOLF_DEBUG(...) \
531 do \
532 { \
533 char this_file[] = __FILE__; \
534 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
535 .debug("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
536 } while (0)
537#define WOLF_DEBUG_COND(cond, ...) \
538 do \
539 { \
540 if (cond) WOLF_DEBUG(__VA_ARGS__); \
541 } while (0)
542#else
543#define WOLF_DEBUG(...) \
544 do \
545 { \
546 } while (0)
547#define WOLF_DEBUG_COND(cond, ...) \
548 do \
549 { \
550 } while (0)
551#endif
552
553#ifdef _WOLF_TRACE
554#define WOLF_TRACE(...) \
555 do \
556 { \
557 char this_file[] = __FILE__; \
558 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
559 .trace("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
560 } while (0)
561#define WOLF_TRACE_COND(cond, ...) \
562 do \
563 { \
564 if (cond) WOLF_TRACE(__VA_ARGS__); \
565 } while (0)
566#else
567#define WOLF_TRACE(...) \
568 do \
569 { \
570 } while (0)
571#define WOLF_TRACE_COND(cond, ...) \
572 do \
573 { \
574 } while (0)
575#endif
576
577#ifdef _WOLF_DEBUG // DEBUG: WOLF_PROC_DEBUG = WOLF_DEBUG
578#define WOLF_PROC_DEBUG(...) WOLF_DEBUG(__VA_ARGS__)
579#elif defined(WOLF_PRETTY_FUNCTION) // RELEASE: print depending on debug_verbose_level_
580#define WOLF_PROC_DEBUG(...) \
581 { \
582 static_assert(std::is_base_of<ProcessorBase, typename std::remove_pointer<decltype(this)>::type>::value, \
583 "WOLF_PROC_DEBUG can only be used in processors"); \
584 /* Check if the caller is a member function of the class 'getType()' */ \
585 bool called_from_derived = wolf::internal::isMemberFunctionOf(WOLF_PRETTY_FUNCTION, getType()); \
586 /* Check if the message should be printed according to debug_verbose_level_ */ \
587 if (debug_verbose_level_ == "all" or (called_from_derived and (debug_verbose_level_ == "derived")) or \
588 (not called_from_derived and (debug_verbose_level_ == "base"))) \
589 { \
590 /* Print as WOLF_DEBUG even if WOLF_DEBUG is disabled (copied from logging.h) */ \
591 char this_file[] = __FILE__; \
592 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
593 .debug("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
594 } \
595 }
596#else // RELEASE & no function signature available --> printing if debug_verbose_level_ != "none"
597#define WOLF_PROC_DEBUG(...) \
598 { \
599 static_assert(std::is_base_of<ProcessorBase, typename std::remove_pointer<decltype(this)>::type>::value, \
600 "WOLF_PROC_DEBUG can only be used in processors"); \
601 /* message will be printed if debug_verbose_level_ != "none" */ \
602 if (debug_verbose_level_ != "none") \
603 { /* Print as WOLF_DEBUG even if WOLF_DEBUG is disabled (copied from logging.h) */ \
604 char this_file[] = __FILE__; \
605 wolf::internal::WolfLogger::get(__INTERNAL_WOLF_MAIN_LOGGER_NAME_) \
606 .debug("[", basename(this_file), " L", __LINE__, "] ", __FUNCTION__, ": ", __VA_ARGS__); \
607 } \
608 }
609#endif
610
611#define WOLF_PROC_DEBUG_COND(cond, ...) \
612 if (cond) WOLF_PROC_DEBUG(__VA_ARGS__);
A thread-safer (?) Singleton implementation with argument forwarding.
Definition: singleton.h:33
Manager of named loggers, created on demand.
Definition: logging.h:313
bool exists(const std::string &name) const
Returns whether a logger exists (thread-safe)
Definition: logging.h:325
const Logger & getLogger(const std::string &name)
Returns a logger, creating it if it does not exist (thread-safe)
Definition: logging.h:333
bool addLogger(const std::string &name)
Creates and adds a logger if it does not exist. Returns whether it was created.
Definition: logging.h:349
std::map< const std::string, const LoggerPtr > logger_map_
Loggers indexed by name.
Definition: logging.h:345
std::mutex mut_
Mutex of the logger map.
Definition: logging.h:343
bool existsImpl(const std::string &name) const
Returns whether a logger exists (not thread-safe)
Definition: logging.h:359
Named logger, wrapping a spdlog color console logger.
Definition: logging.h:103
void error(Args &&... args) const
Logs an error message composed of the arguments.
Definition: logging.h:265
void info(Args &&... args) const
Logs an info message composed of the arguments.
Definition: logging.h:245
void operator=(Logger &)=delete
Copy assignment (deleted)
Logger(const std::string &name)
Constructor from the logger name.
Definition: logging.h:173
void set_pattern(const std::string &p)
Sets the spdlog pattern of the messages.
Definition: logging.h:303
void debug(Args &&... args) const
Logs a debug message composed of the arguments.
Definition: logging.h:275
bool set_async_queue(const std::size_t q_size)
Initializes the spdlog thread pool for asynchronous logging with a queue size (only if it is even)
Definition: logging.h:294
~Logger()
Destructor, dropping the spdlog logger.
Definition: logging.h:239
Logger(Logger &&)=delete
Move constructor (deleted)
const std::string log_name_
Name of the logger.
Definition: logging.h:168
void operator=(Logger &&)=delete
Move assignment (deleted)
Logger(Logger &)=delete
Copy constructor (deleted)
void trace(Args &&... args) const
Logs a trace message composed of the arguments.
Definition: logging.h:285
void warn(Args &&... args) const
Logs a warning message composed of the arguments.
Definition: logging.h:255
std::shared_ptr< spdlog::logger > console_
spdlog logger
Definition: logging.h:170
#define __INTERNAL_WOLF_MAIN_LOGGER_NAME_
Definition: logging.h:42
Definition: jet.h:1355
static constexpr auto repeated_brace
Definition: logging.h:44
std::unique_ptr< Logger > LoggerPtr
Definition: logging.h:308
bool isMemberFunctionOf(const std::string &_function_signature, const std::string &_class_name)
Checks if a function signature corresponds to a member function of the class wolf::_class_name.
Definition: logging.h:376
Definition: capture_base.h:23